//
//  ListInterfaceController.swift
//  WatchKitPreview
//
//  Created by 王儒林 on 15/8/27.
//  Copyright (c) 2015年 王儒林. All rights reserved.
//

import WatchKit
import Foundation


class ListInterfaceController: WKInterfaceController {
    
    let tableDataSource :[[String:String]] = [
        ["title":"title0","description":"description0"],
        ["title":"title1","description":"description1"],
        ["title":"title2","description":"description2"],
        ["title":"title3","description":"description3"],
        ["title":"title4","description":"description4"],
        ["title":"title5","description":"description5"],
    ]
    @IBOutlet weak var table: WKInterfaceTable!
    @IBOutlet weak var theOtherTable: WKInterfaceTable!

    override func awakeWithContext(context: AnyObject?) {
        super.awakeWithContext(context)
        setTitle("列表页")
        table.setNumberOfRows(tableDataSource.count, withRowType: "MyRowController")
        for (i, value) in enumerate(tableDataSource) {
            if let rowController = table.rowControllerAtIndex(i) as? MyRowController {
                rowController.info = value
            }
        }
        theOtherTable.setNumberOfRows(3, withRowType: "TheOtherRowController")
    }

    override func willActivate() {
        // This method is called when watch view controller is about to be visible to user
        super.willActivate()
    }

    override func didDeactivate() {
        super.didDeactivate()
    }
    
    override func table(table: WKInterfaceTable, didSelectRowAtIndex rowIndex: Int) {
        if table == self.table {
            presentControllerWithNames(["page0","page1","page2"], contexts: nil)
        } else if theOtherTable == table {
            pushControllerWithName("page1", context: nil)
        }
    }

}
